package team18.yuejian.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.squareup.picasso.Picasso;

import java.util.List;
import team18.yuejian.Activity.MineListActivity;
import team18.yuejian.Model.RetrofitModel;
import team18.yuejian.R;
import team18.yuejian.bean.FocusBean;

public class MineFocusAdapter extends RecyclerView.Adapter<MineFocusAdapter.ViewHolder> {
    private Context mcontext;
    private List<FocusBean> mLists;


    static class ViewHolder extends RecyclerView.ViewHolder{
        CardView cardView;
        LinearLayout mlayout;
        TextView typeTitle,type,operation,name;
        ImageView mPic;

        public ViewHolder(View view){
            super(view);
            cardView = (CardView) view;
            mlayout = view.findViewById(R.id.MineList_LinearLayout);
            typeTitle = view.findViewById(R.id.cardview_order_list_typetitle);
            type = view.findViewById(R.id.cardview_order_list_type);
            operation = view.findViewById(R.id.cardview_order_list_operation);
            mPic = view.findViewById(R.id.cardview_order_list_pic);
            name = view.findViewById(R.id.cardview_order_list_oname);
        }

    }

    public MineFocusAdapter(List<FocusBean> lists){
        mLists = lists;
    }

    @Override
    public MineFocusAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mcontext == null){
            mcontext = parent.getContext();
        }

        View view = LayoutInflater.from(mcontext).inflate(R.layout.cardview_order_list_item,parent,false);

        return new MineFocusAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MineFocusAdapter.ViewHolder holder, int position) {
            RetrofitModel retrofitModel = new RetrofitModel();
            String url = retrofitModel.getPicUrl();
            final FocusBean focusBean = mLists.get(position);
            holder.operation.setText("删除");
            holder.typeTitle.setText("俱乐部");
            holder.type.setText(focusBean.getFtime());
            holder.name.setText(focusBean.getCname());
            Picasso.with(mcontext).load(url+"/clubimage/"+focusBean.getCpic()).into(holder.mPic);

            holder.operation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(mcontext,MineListActivity.class);
                    intent.putExtra("type",2);
                    intent.putExtra("delete",focusBean.getFid());
                    mcontext.startActivity(intent);
                }
            });
    }

    @Override
    public int getItemCount() {
        return mLists.size();
    }
}
